package cn.edu.scau.dao;

import cn.edu.scau.entity.Manager;
import cn.edu.scau.entity.Nurse;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
@CacheNamespace
public interface NurseMapper {
    @Delete({
            "delete from nurse",
            "where nurseID = #{nurseid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer nurseid);

    @Insert({
            "insert into nurse (nurseID, userId, ",
            "nursename, nurseSex, ",
            "nurseAge, nurseUseflag)",
            "values (#{nurseid,jdbcType=INTEGER}, #{userid,jdbcType=INTEGER}, ",
            "#{nursename,jdbcType=VARCHAR}, #{nursesex,jdbcType=VARCHAR}, ",
            "#{nurseage,jdbcType=INTEGER}, #{nurseuseflag,jdbcType=BIT})"
    })
    @Options(useGeneratedKeys = true,keyColumn = "nurseID",keyProperty = "nurseid")
    int insert(Nurse record);

    @InsertProvider(type=NurseSqlProvider.class, method="insertSelective")
    int insertSelective(Nurse record);

    @Select({
            "select",
            "nurseID, userId, nursename, nurseSex, nurseAge, nurseUseflag",
            "from nurse",
            "where nurseID = #{nurseid,jdbcType=INTEGER} and nurseUseflag = true"
    })
    @Results({
        @Result(column="nurseID", property="nurseid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="nursename", property="nursename", jdbcType=JdbcType.VARCHAR),
        @Result(column="nurseSex", property="nursesex", jdbcType=JdbcType.VARCHAR),
        @Result(column="nurseAge", property="nurseage", jdbcType=JdbcType.INTEGER),
        @Result(column="userId", property="userid", jdbcType=JdbcType.INTEGER),
        @Result(column="nurseUseflag", property="nurseuseflag", jdbcType=JdbcType.BIT)
    })
    Nurse selectByPrimaryKey(Integer nurseid);
    /**
     * 根据护士编号,用户编号,护士姓名模糊查询
     * @param nurseID,userId,nursename
     * @return 返回部门信息对象
     */
    @SelectProvider(type = NurseSqlProvider.class,method = "findByIdUseidName")
    List<Nurse> findByIdUseidName(@Param("nurseID") Integer nurseID,@Param("userId") Integer userId,@Param("nursename") String nursename);
    @Select({
            "select",
            "nurseID, userId, nursename, nurseSex, nurseAge, nurseUseflag",
            "from nurse",
            "where userId = #{userid,jdbcType=INTEGER} and nurseUseflag = true"
    })
    @Results({
            @Result(column="nurseID", property="nurseid", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="nursename", property="nursename", jdbcType=JdbcType.VARCHAR),
            @Result(column="nurseSex", property="nursesex", jdbcType=JdbcType.VARCHAR),
            @Result(column="nurseAge", property="nurseage", jdbcType=JdbcType.INTEGER),
            @Result(column="userId", property="userid", jdbcType=JdbcType.INTEGER),
            @Result(column="nurseUseflag", property="nurseuseflag", jdbcType=JdbcType.BIT)
    })
    Nurse selectByUserId(Integer userid);
    @Select({
            "select",
            "nurseID, userId, nursename, nurseSex, nurseAge, nurseUseflag",
            "from nurse",
            "where nurseUseflag = true"
    })
    List<Nurse> selectAll();

    @UpdateProvider(type=NurseSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Nurse record);

    @Update({
            "update nurse",
            "set userId = #{userid,jdbcType=INTEGER},",
            "nursename = #{nursename,jdbcType=VARCHAR},",
            "nurseSex = #{nursesex,jdbcType=VARCHAR},",
            "nurseAge = #{nurseage,jdbcType=INTEGER},",
            "nurseUseflag = #{nurseuseflag,jdbcType=BIT}",
            "where nurseID = #{nurseid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Nurse record);
}